/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pb138.videodes.impl;

import com.thoughtworks.xstream.XStream;
import cz.muni.fi.pb138.videodes.api.base.RowMapper;
import cz.muni.fi.pb138.videodes.entity.Genre;
import cz.muni.fi.pb138.videodes.entity.Movie;
import org.xmldb.api.base.Resource;
import org.xmldb.api.base.XMLDBException;

/**
 *
 * @author pseudo
 */
public class MovieRowMapper implements RowMapper<Movie> {

    @Override
    public Movie map(Resource rs) throws XMLDBException {
	XStream x = new XStream();
	x.alias("movie", Movie.class);
	x.alias("actor", String.class);
	x.alias("genre", Genre.class);

	Movie movie = (Movie) x.fromXML(rs.getContent().toString());
	movie.setId(rs.getId());
	return movie;
    }
    
}
